fix(validation): remove polynomial ReDoS in email regexes#2688
Merged
Conversation
The email validators used `/^[^\s@]+@[^\s@]+\.[^\s@]+$/`. Because the literal `.` is also a member of `[^\s@]`, the quantifiers on either side of `\.` overlap, so the pattern backtracks polynomially on adversarial input (CodeQL polynomial-redos, #2681). Rewrite the domain part as `[^\s@.]+(?:\.[^\s@.]+)+` so labels exclude `.`; the quantifiers around each dot no longer overlap and matching is linear. Semantics are preserved for valid addresses (local `@` dotted domain, multi-label domains still accepted); consecutive dots — an empty, invalid label — are now correctly rejected. Applied to all three copies of the pattern: - packages/objectql/src/validation/record-validator.ts - packages/objectql/src/validation/rule-validator.ts - packages/plugins/plugin-email/src/email-service.ts Add rule-validator tests covering multi-label domains, empty-label rejection, and a linear-time (no-ReDoS) adversarial-input guard. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CajRFHqgkDMjV6xxDKbPec
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
📓 Docs Drift CheckThis PR changes 2 package(s): 13 hand-written doc(s) reference the affected code and may need an implementation-accuracy re-verification:
|
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CajRFHqgkDMjV6xxDKbPec
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the CodeQL polynomial regex (ReDoS) finding (#2681) in the email
validators.
All three copies of the email pattern used:
Because the literal
.is itself a member of[^\s@], the quantifiers oneither side of
\.overlap, so the engine backtracks polynomially onadversarial input (a long run of domain-ish characters with no valid
terminator).
The domain part is rewritten so labels exclude
.:Now the quantifiers around each dot no longer overlap and matching is
linear. Semantics are preserved for valid addresses (local part
@dotted domain; multi-label domains like
a@b.co.ukstill accepted). Theonly behavioural change is that consecutive dots — an empty, invalid label
such as
a@b..c— are now correctly rejected.Changes
packages/objectql/src/validation/record-validator.ts—EMAIL_REpackages/objectql/src/validation/rule-validator.ts—EMAIL_REpackages/plugins/plugin-email/src/email-service.ts—EMAIL_REGEX(same pattern, same vulnerability — fixed for consistency)
packages/objectql/src/validation/rule-validator.test.ts— new testsfor multi-label domains, empty-label rejection, and a linear-time
(no-ReDoS) adversarial-input guard.
Verification
objectqlvalidator suites: 48 passing (incl. new tests)plugin-emailsuites: 61 passingobjectqlbuilds cleanly (ESM/CJS/DTS)input where the old one backtracks.
Note:
content/docs/protocol/objectui/concept.mdxshows the old pattern asan illustrative example only (docs, not shipped code) and is intentionally
left unchanged.
service-messaging/recipient-resolver.tsalready uses ahand-rolled linear check and documents this exact concern.
🤖 Generated with Claude Code
https://claude.ai/code/session_01CajRFHqgkDMjV6xxDKbPec
Generated by Claude Code